package com.lin.utils;

public class TestUtil {
    // 将int转换为无符号整数
    public static int toUnsigned(int num) {
        return num & 0xFFFFFFFF;
    }

    // 将字符串转换为无符号整数
    public static int parseUnsigned(String s) {
        return Integer.parseUnsignedInt(s);
    }

    // 比较两个无符号整数的大小
    public static int compare(int a, int b) {
        return Integer.compareUnsigned(a, b);
    }

    public static void main(String[] args) {
        int num1 = -1; // 0xFFFFFFFF
        int num2 = Integer.MAX_VALUE; // 0xFFFFFFFF

        // 转换为无符号整数
        int unsignedNum1 = toUnsigned(num1);
        int unsignedNum2 = toUnsigned(num2);

        // 打印结果
        System.out.println("Unsigned " + num1 + ": " + unsignedNum1);
        System.out.println("Unsigned " + num2 + ": " + unsignedNum2);

        // 比较两个无符号整数
        int comparisonResult = compare(unsignedNum1, unsignedNum2);
        System.out.println("Comparison result: " + comparisonResult);

        // 解析字符串为无符号整数
        int parsedUnsigned = parseUnsigned("4294967295");
        String unsignedString = Integer.toUnsignedString(parsedUnsigned);
        System.out.println("Parsed unsigned: " + parsedUnsigned);
        System.out.println("Parsed unsigned: " + unsignedString);
    }
}
